package ca.liu.scaffoldingmvctest.service;

import ca.liu.scaffoldingmvctest.domain.StLog;
import ca.liu.scaffoldingmvctest.domain.StUser;

import java.util.List;
import java.util.Set;

import org.junit.Test;

import org.junit.runner.RunWith;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.beans.factory.support.DefaultListableBeanFactory;

import org.springframework.context.ApplicationContext;

import org.springframework.mock.web.MockHttpServletRequest;

import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;

import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
import org.springframework.test.context.support.DirtiesContextTestExecutionListener;

import org.springframework.test.context.transaction.TransactionalTestExecutionListener;

import org.springframework.transaction.annotation.Transactional;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.RequestScope;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.context.request.SessionScope;

/**
 * Class to run the service as a JUnit test. Each operation in the service is a separate test.
 *
 */

@RunWith(SpringJUnit4ClassRunner.class)
@TestExecutionListeners({
		DependencyInjectionTestExecutionListener.class,
		DirtiesContextTestExecutionListener.class,
		TransactionalTestExecutionListener.class })
@ContextConfiguration(locations = {
		"file:./src/main/resources/scaffoldingmvctest-security-context.xml",
		"file:./src/main/resources/scaffoldingmvctest-service-context.xml",
		"file:./src/main/resources/scaffoldingmvctest-dao-context.xml",
		"file:./src/main/resources/scaffoldingmvctest-web-context.xml" })
@Transactional
public class StUserServiceTest {

	/**
	 * The Spring application context.
	 *
	 */
	@SuppressWarnings("unused")
	private ApplicationContext context;

	/**
	 * The service being tested, injected by Spring.
	 *
	 */
	@Autowired
	protected StUserService service;

	/**
	 * Instantiates a new StUserServiceTest.
	 *
	 */
	public StUserServiceTest() {
		setupRequestContext();
	}

	/**
	 * Operation Unit Test
	 * Save an existing StLog entity
	 * 
	 */
	@Test
	public void saveStUserStLogs() {
		// TODO: JUnit - Populate test inputs for operation: saveStUserStLogs 
		Integer id = 0;
		StLog related_stlogs = new ca.liu.scaffoldingmvctest.domain.StLog();
		StUser response = null;
		response = service.saveStUserStLogs(id, related_stlogs);
		// TODO: JUnit - Add assertions to test outputs of operation: saveStUserStLogs
	}

	/**
	 * Operation Unit Test
	 * Save an existing StUser entity
	 * 
	 */
	@Test
	public void saveStUser() {
		// TODO: JUnit - Populate test inputs for operation: saveStUser 
		StUser stuser = new ca.liu.scaffoldingmvctest.domain.StUser();
		service.saveStUser(stuser);
	}

	/**
	 * Operation Unit Test
	 * Delete an existing StUser entity
	 * 
	 */
	@Test
	public void deleteStUser() {
		// TODO: JUnit - Populate test inputs for operation: deleteStUser 
		StUser stuser_1 = new ca.liu.scaffoldingmvctest.domain.StUser();
		service.deleteStUser(stuser_1);
	}

	/**
	 * Operation Unit Test
	 */
	@Test
	public void findStUserByPrimaryKey() {
		// TODO: JUnit - Populate test inputs for operation: findStUserByPrimaryKey 
		Integer id_1 = 0;
		StUser response = null;
		response = service.findStUserByPrimaryKey(id_1);
		// TODO: JUnit - Add assertions to test outputs of operation: findStUserByPrimaryKey
	}

	/**
	 * Operation Unit Test
	 * Return a count of all StUser entity
	 * 
	 */
	@Test
	public void countStUsers() {
		Integer response = null;
		response = service.countStUsers();
		// TODO: JUnit - Add assertions to test outputs of operation: countStUsers
	}

	/**
	 * Operation Unit Test
	 * Delete an existing StLog entity
	 * 
	 */
	@Test
	public void deleteStUserStLogs() {
		// TODO: JUnit - Populate test inputs for operation: deleteStUserStLogs 
		Integer stuser_id = 0;
		Integer related_stlogs_id = 0;
		StUser response = null;
		response = service.deleteStUserStLogs(stuser_id, related_stlogs_id);
		// TODO: JUnit - Add assertions to test outputs of operation: deleteStUserStLogs
	}

	/**
	 * Operation Unit Test
	 * Return all StUser entity
	 * 
	 */
	@Test
	public void findAllStUsers() {
		// TODO: JUnit - Populate test inputs for operation: findAllStUsers 
		Integer startResult = 0;
		Integer maxRows = 0;
		List<StUser> response = null;
		response = service.findAllStUsers(startResult, maxRows);
		// TODO: JUnit - Add assertions to test outputs of operation: findAllStUsers
	}

	/**
	 * Operation Unit Test
	 * Load an existing StUser entity
	 * 
	 */
	@Test
	public void loadStUsers() {
		Set<StUser> response = null;
		response = service.loadStUsers();
		// TODO: JUnit - Add assertions to test outputs of operation: loadStUsers
	}

	/**
	 * Autowired to set the Spring application context.
	 *
	 */
	@Autowired
	public void setContext(ApplicationContext context) {
		this.context = context;
		((DefaultListableBeanFactory) context.getAutowireCapableBeanFactory()).registerScope("session", new SessionScope());
		((DefaultListableBeanFactory) context.getAutowireCapableBeanFactory()).registerScope("request", new RequestScope());
	}

	/**
	 * Sets Up the Request context
	 *
	 */
	private void setupRequestContext() {
		MockHttpServletRequest request = new MockHttpServletRequest();
		ServletRequestAttributes attributes = new ServletRequestAttributes(request);
		RequestContextHolder.setRequestAttributes(attributes);
	}
}
